<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
        class="buttons">导出</el-button>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="所属院系" prop="userName">
        <el-select v-model="queryParams.deptId" placeholder="请选择" clearable class="elSelect" @change="handleChange"  style="width: 100%">
                <el-option v-for="item in deptOptions" :key="item.deptId" :label="item.deptName"
                  :value="item.deptId"></el-option>
              </el-select>
        <!-- <el-cascader
          v-model="queryParams.deptId"
          :options="deptOptions"
          :props="{ value: 'id',currentLabels: 'label',checkStrictly: true}"
          @change="handleChange"
    ></el-cascader> -->
      </el-form-item>
      <el-form-item label="类型">
          <el-select v-model="remarkList" multiple  placeholder="请选择" clearable class="elSelect" @change="remakArry">
                  <el-option
                    v-for="dict in dict.type.basic_speciality_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="query">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="paramsQuery">重置</el-button>
        
      </el-form-item>
    </el-form>
      
    </el-row>
    <el-table :data="gradeSummaryList">
      <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
      <el-table-column label="所属院系" prop="deptName" width="200" align="center"></el-table-column>

      <el-table-column label="总人数" prop="numberTotal" align="center"></el-table-column>
      <el-table-column label="班级总数" prop="classSizeTotal" align="center"></el-table-column>
      <el-table-column label="男生总数" prop="bTotal" align="center"></el-table-column>
      <el-table-column label="女生总数" prop="fTotal" align="center"></el-table-column>
      <el-table-column label="毕业班" align="center">
        <el-table-column label="毕业班级数" prop="gradeClassTotal" align="center"></el-table-column>
      <el-table-column label="毕业班男生数" prop="gradeBTotal" align="center"></el-table-column>
      <el-table-column label="毕业班女生数" prop="gradeFTotal" align="center"></el-table-column>
      <el-table-column label="毕业班总人数" prop="gradeTotal" align="center"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
      </el-table-column>
     
    </el-table>
    <!-- 查看详情弹窗 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form :model="form" ref="queryForm" :inline="true">
        <el-form-item label="所在年级">
          <el-select v-model="form.gradeId" clearable placeholder="请选择">
            <el-option v-for="item in gradeDate" :key="item.VALUE" :label="item.TITILE" :value="item.VALUE"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型">
          <!-- <el-select v-model="form.remark" clearable placeholder="请选择">
            basic_speciality_type
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select> -->
          <el-select v-model="form.remark" placeholder="请选择" clearable class="elSelect">
                  <el-option
                    v-for="dict in dict.type.basic_speciality_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="deptExport">导出</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="list" border>
        <el-table-column label="学年" prop="gradeName" align="center" width="100"></el-table-column>
        <el-table-column label="院系汇总" align="center">
          <template slot-scope="scope">
            <el-table :data="scope.row.typeSummaryList">
              <el-table-column label="类型" prop="specialityType" align="center"></el-table-column>

              <el-table-column label="班级数" prop="classSize" align="center"></el-table-column>

              <el-table-column label="总人数"  prop="numberSize" align="center">
              </el-table-column>
              <el-table-column label="人数" align="center">
                <el-table-column label="男生" prop="maleNumberSize" align="center"></el-table-column>
                <el-table-column label="女生" prop="femaleNumberSize" align="center"></el-table-column>
              </el-table-column>

              <el-table-column label="毕业班" align="center">
                <el-table-column label="毕业班级数" prop="gradeClassTotal" align="center"></el-table-column>
              <el-table-column label="毕业班男生数" prop="gradeBTotal" align="center"></el-table-column>
              <el-table-column label="毕业班女生数" prop="gradeFTotal" align="center"></el-table-column>
              <el-table-column label="毕业班总人数" prop="gradeTotal" align="center"></el-table-column>
              </el-table-column>
             
            </el-table>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { statisticsSummary, statisticsSummaryInfo,statSummaryCount } from "@/api/information/summary";
import { getGradeSelect } from "@/api/information/gradeInfor";
import { deptTreeSelect } from "@/api/system/user";
import {
  collegeSelect
} from "@/api/information/studentInfor"
export default {
  dicts: ['basic_speciality_type'],
  data() {
    return {
      gradeSummaryList: [],
      open: false,
      list: [],
      title: "",
      form: {
        deptId: '',
        remark: '',
        gradeId: ''
      },
      queryParams: {
        deptId:'',
        remark: ''
      },
      remarkList: [],
      deptOptions: [],
      // 获取年级下拉数据
      gradeDate: [],

    };
  },
  created() {
    this.getDeptTree()
    this.getlist()
  },
  methods: {
   
    getlist() { 
      statSummaryCount(this.queryParams).then(res => {
      console.log(res);
      this.gradeSummaryList = res.data;
    });
    //   statisticsSummary(this.queryParams).then(res => {
    //   console.log(res);
    //   this.gradeSummaryList = res.data;
    // });
    },
    // 类型多选
    remakArry(data) {
      this.queryParams.remarks = data.join(',');
      console.log(this.queryParams.remarks)
    },
    handleExport() {
      this.download(
        "/basic/student/statisticsSummary/export",
        {},
        `学院汇总${new Date().getFullYear()}-${new Date().getMonth() +
        1}-${new Date().getDate()}.xlsx`
      );
    },
    deptExport() {
      this.download(
        "/basic/student/statisticsTypeSummary/export",
        {...this.form},
        `二级学院汇总${new Date().getFullYear()}-${new Date().getMonth() +
        1}-${new Date().getDate()}.xlsx`
      );
    },
    handleChange(value) {
      // if (typeof value == "object") {
      //   this.queryParams.deptId = value[value.length - 1];  
      // }
    },
    paramsQuery() {
      this.queryParams.deptId = ''
      this.queryParams.remark = ''
      this.getlist()
    },
     /** 查询部门下拉树结构 */
     getDeptTree() {
      collegeSelect().then(response => {
        console.log(response);
        this.deptOptions = response.data;
        // this.queryParams.deptId = response.data[0].id;
        this.getGradeInfor();
      });
    },
    query() {
      console.log(this.queryParams,'dfasdfds')
      this.getlist()
    },
    handleView(row) {
      this.getGradeInfor()
      this.title = "二级学院汇总";
      this.open = true;
      this.form = row
      console.log(this.form, ';fff')
      this.getInforList(this.form)
      // this.list = row.gradeSummaryList;
    },
    // 获取详情数据
    getInforList(data) {
      statisticsSummaryInfo(data).then(res => {
        this.list = res.data
      })
    },
    handleQuery(){
      this.getInforList(this.form)
    },
    resetQuery(){
      this.form.gradeId = ''
      this.form.remark = ''
      this.getInforList(this.form)
    },
    getGradeInfor() {
      getGradeSelect(this.queryParams).then(response => {
        // console.log(response, "Student");
        this.gradeDate = response.data;
      });
    },
  }
};
</script>

<style scoped>
.buttons {
  display: inline-block;
  float: right;
  text-align: right;
  margin-right: 5%;
}
</style>